//
//  QGDetailViewController.m
//  shuiyun
//
//  Created by edz on 2017/9/7.
//  Copyright © 2017年 qianyi. All rights reserved.
//

#import "QGDetailViewController.h"
#import "QGDetailTableViewCell.h"
#import "QGDetailAnotherTableViewCell.h"
#import "HomeshipJYAnotherViewController.h"

@interface QGDetailViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
//@property (nonatomic, strong) NSMutableArray *dataArr;

@property(nonatomic,strong)NSMutableDictionary * dict;
@end

@implementation QGDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setUpData];
    
    [self creationView];
    [self regeditCell];
    [self setTitle:@"船舶求购详情"];
    self.view.backgroundColor = [UIColor blackColor];
    
    /*
    UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, DEF_SCREEN_WIDTH, 40)];
    lab.text = @"发布信息：2017/ 07/ 27/  15:33";
    lab.font = [UIFont systemFontOfSize:14];
    lab.textAlignment = NSTextAlignmentCenter;
    lab.backgroundColor = [UIColor whiteColor];
    lab.textColor = [UIColor colorWithRed:102/255.0f green:102/255.0f blue:102/255.0f alpha:1];
    [self.view addSubview:lab];
    */
}

- (void)creationView{
    
    self.tableView = [[UITableView alloc] init];
    self.tableView.frame = CGRectMake(0, 0, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT - 64);
    self.tableView.tableFooterView = [[UITableView alloc] initWithFrame:CGRectZero];
    
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.separatorStyle = UITableViewCellAccessoryNone;//去掉分割线
    self.tableView.estimatedRowHeight = 800;
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    
}


- (void)regeditCell{
    
    [self.tableView registerNib:[UINib nibWithNibName:@"QGDetailTableViewCell" bundle:nil] forCellReuseIdentifier:@"QGDetailTableViewCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"QGDetailAnotherTableViewCell" bundle:nil] forCellReuseIdentifier:@"QGDetailAnotherTableViewCell"];
    
}

-(void)setUpData{
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[[UIApplication sharedApplication]keyWindow] animated:YES];
    hud.tag = 500;
    //提示文本
    hud.labelText = @"正在加载...";
    //是否有遮罩
    hud.dimBackground = YES;
    

    _dict = [NSMutableDictionary dictionary];
    
    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    
    
    NSString *token = [PublicFunction getConfigWithKey:@"token"];
    [productParams setValue:token forKey:@"token"];
    NSString * userid = [PublicFunction getConfigWithKey:@"userid"];
    [productParams setValue:userid forKey:@"userid"];
    [productParams setValue:self.idStr forKey:@"id"];
    
    [[MNetworkHandler sharedInstance]conURL:HomeDealDetail  networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
        NSLog(@"%@", returnData);
        NSLog(@"%@", productParams);
        
        if ([[returnData objectForKey:@"code"]intValue]==1) {
            
            _dict = [returnData objectForKey:@"data"];
            NSLog(@"!!!!!!!!!!!!!!!%@",_dict);
            
           // self.label2.text = [_dict objectForKey:@"newstime"];
            
            [self.tableView reloadData];
            [hud removeFromSuperview];
        }
        
        else {
            
            [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
            
            [hud removeFromSuperview];
        }
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
        [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
        
        [hud removeFromSuperview];        
    }];
    
    

}


#pragma mark - ---------- Section的数量 ----------
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
#pragma mark - ---------- 每个Section的高度 ----------
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0;
}
//section 不随tableView滑动
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
    if (scrollView == self.tableView)
        
    {
        
        CGFloat sectionHeaderHeight = 64; //header高度
        
        if (scrollView.contentOffset.y <= sectionHeaderHeight && scrollView.contentOffset.y >= 0) {
            
            scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
            
        } else if (scrollView.contentOffset.y >= sectionHeaderHeight) {
            
            scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
            
        }
        
    }
    
    
    
}
#pragma mark - ---------- Cell的数量 ----------
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    
    return 2;
    
}

#pragma mark - ---------- 每个Cell的高度 ----------
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.row == 0) {
        return 220;
    }else {
        
        return UITableViewAutomaticDimension;
    }
    
}
#pragma mark - ---------- 每个Cell的内容 ----------
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 0) {
        
        QGDetailTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"QGDetailTableViewCell" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        cell.priceLabel.text = [_dict objectForKey:@"price"];
        cell.boatStyleLabel.text = [_dict objectForKey:@"boat"];
        cell.creatTimeLabel.text = [_dict objectForKey:@"c_time"];
        cell.boatLengthLabel.text = [_dict objectForKey:@"chang"];
        cell.boatWidthLabel.text = [_dict objectForKey:@"kuan"];
        cell.boatDeepLabel.text = [_dict objectForKey:@"shen"];
        
        return cell;
        
    }else {
        
        QGDetailAnotherTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"QGDetailAnotherTableViewCell" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        cell.nameLabel.text = [_dict objectForKey:@"linkman"];
        cell.phoneLabel.text = [_dict objectForKey:@"phone"];
        cell.contentLabel.text = [_dict objectForKey:@"connect"];
        
        return cell;
        
    
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
